package cs343;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;

/**
 * <p>Title: CS 343 Project: Pong</p>
 * <p>Description: CS 343 Project
 * Using JFrame and JButtons, this class creates a menu for the user to 
 * select different options for the game. The user cam either veiw the top
 * five high scores for Pong, can play the game, or can exit.</p>
 * @author Jenny Windsperger, Stirling Pankow, Will Prew, Shane O'Malley-Potting
 * @email jennifer.windsperger@my.uwrf.edu, stirling.pankow@my.uwrf.edu, william.prew@my.uwrf.edu, shane.omalley-potting@my.uwrf.edu
 * @date December 1st 2011
 */

public class Main {
	public static void main(String[] args) {
		//create JFrame for the menu
		final JFrame frame = new JFrame();

		//create button to play pong
		JButton button = new JButton("Play Pong");
		frame.add(button);
		
		//if button is clicked, open up the pong arena
		button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                ArenaContainer playPong = new ArenaContainer();
                playPong.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                playPong.setVisible(true);
            }
        });
		
		//create a button the view high scores
		JButton button2 = new JButton("View High Scores");
		frame.add(button2);
		
		//if the button is clicked, add a JList to the menu screen displaying the top five scores
		button2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				HighScores scores = new HighScores();
				String[] highScores = new String[6];
				highScores[0] = "High Scores:";
				for (int i = 0; i < 5; i++) {
					highScores[i + 1] = scores.getHighScores().get(i).toString();
				}
				JList scorelabels = new JList(highScores);
				scorelabels.setFont(new Font("Courier New", Font.PLAIN, 24));
				frame.add(scorelabels);
				frame.setVisible(true);
			}
		});
		
		//create a button to exit the program
		JButton button3 = new JButton("Exit");
		frame.add(button3);
		
		//if the button is clicked, terminate the program
		button3.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		
		frame.setLayout(new FlowLayout());
		//set the size of the frame and set the background to black
		frame.setSize(400, 325);
		Container con = frame.getContentPane();
		con.setBackground( Color.BLACK ); 
		frame.setVisible(true);
	}

	//if the frame is closed, the program will terminate
	public void windowClosing(WindowEvent e) {
		System.exit(0);
	}

}
